package com.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.entity.Lose;
import com.service.LoseService;
import com.vo.ResultVo;

@Controller
public class LostController {
	@Autowired 
	LoseService loseService;
	
	/**插入失物*/
	@ResponseBody
	@RequestMapping("/con/insertLose")
	public ResultVo insertLose(@RequestBody Lose lose ) {
	    	System.err.println(lose);
	    	
	    	ResultVo rv=new ResultVo();
	    	try {
	    		this.loseService.insertLose(lose);
	    		rv.setMessage("插入信息成功");
		    	return rv;
				
			} catch (Exception e) {
				// TODO: handle exception 
	    	    System.err.println("代码异常");
				rv.setMessage("插入信息失败");
				e.printStackTrace();
		    	return rv;
			}
	    
	}
	
	/**查询全部失物记录 */
	@ResponseBody
	@RequestMapping("/con/lookLose")
	public ResultVo lookLose(@RequestBody Lose lose) {
	    	System.err.println(lose);
	    	
	    	ResultVo rv=new ResultVo();
	    	try {
	    		List<Lose> data= this.loseService.lookLose(lose);;
		    	rv.setMessage("查询信息成功");
		    	rv.setData(data);
		    	return rv;
			} catch (Exception e) {
				// TODO: handle exception
				System.err.println("代码异常");
				rv.setMessage("插入信息失败");
				e.printStackTrace();
			    return rv;
			}
	    	
	}
	
	/**查询某一条失物记录 */
	@ResponseBody
	@RequestMapping("/con/lookIdLose")
	public ResultVo lookIdLose(@RequestBody Integer lose_id) {
	    	System.err.println(lose_id);
	    	
	    	ResultVo rv=new ResultVo();
	    	try {
	    		Lose data= this.loseService.lookIdLose(lose_id);
		    	rv.setMessage("查询信息成功");
		    	rv.setData(data);
		    	return rv;
			} catch (Exception e) {
				// TODO: handle exception
				System.err.println("代码异常");
				rv.setMessage("查询信息失败");
				e.printStackTrace();
			    return rv;
			}
	}
	
	/**修改一条失物的失物记录*/
	@ResponseBody
	@RequestMapping("/con/updateLose")
	public ResultVo updateLose(@RequestBody Lose lose) {
	    	System.err.println(lose);
	    	
	    	ResultVo rv=new ResultVo();
	    	try {
	    		this.loseService.updateLose(lose);
		    	rv.setMessage("修改信息成功");
		    	return rv;
			} catch (Exception e) {
				// TODO: handle exception
				System.err.println("代码异常");
				rv.setMessage("修改信息失败");
				e.printStackTrace();
			    return rv;
			}
	}
	
	/**删除一条具体的失物记录*/
	@ResponseBody
	@RequestMapping("/con/deleteLose")
	public ResultVo deleteLose(@RequestBody Integer lose_id) {
	    	System.err.println(lose_id);
	    	
	    	ResultVo rv=new ResultVo();
	    	try {
	    		this.loseService.deleteLose(lose_id);
		    	rv.setMessage("删除信息成功");
		    	return rv;
			} catch (Exception e) {
				// TODO: handle exception
				System.err.println("代码异常");
				rv.setMessage("修改信息失败");
				e.printStackTrace();
			    return rv;
			}
	    	
	}


}
